package hlhj.fhp.checkpoint.atys

import android.content.Intent
import android.graphics.Color
import android.view.View
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.iview.OrderView
import hlhj.fhp.checkpoint.javaBean.YearDetailBean
import hlhj.fhp.checkpoint.presenter.OrderDetailPresenter
import kotlinx.android.synthetic.main.aty_order_detail.*
import kotlinx.android.synthetic.main.lo_pub_head.*

/**
 * Created by Never Fear   on 2018\11\12 0012.
Never More....
 */
class OrderDetailAty:BaseAty<OrderView,OrderDetailPresenter>(), OrderView {
    override fun initView() {
        tvTittle.text = "订单详情"

        id=intent.getIntExtra("id",-1)
    }
    private var id:Int=-1
    private var offer:String?=""
    override fun logicStart() {
        presenter?.getDetail(id,this)

    }

    private val GOTOFEE: Int=12226

    override fun setListener() {
        loPay.setOnClickListener {
            val intent = Intent(this, PayAty::class.java)
            intent.putExtra("id",id.toString())
            intent.putExtra("money",tvPrice.text.toString())
            intent.putExtra("offer",offer)
            intent.putExtra("orderType",1)
            startActivityForResult(intent,GOTOFEE)
        }
    }


    override fun setDetail(yearDetailBean: YearDetailBean) {
        try {
            val bean = yearDetailBean?.info
            orderNum.text= bean.order_number.toString()
            plateNum.text= bean.plate_number.toString()
            vinNum.text= bean.vin.toString()
            enginNum.text= bean.engine_number.toString()
            tvTime.text= bean.examine_date.toString()
            tvPrice.text= bean.original_price
            if (bean?.original_price!=null&&bean?.offer!=null){
                tvTotal.text="${bean.original_price.toDouble()+bean.offer.toDouble()}"
            }

            tvOffer.text="加服务费${bean.offer}元"
            offer=bean?.offer
            when(bean.status){
                0->{
                    itemState.visibility=View.GONE
                    loPay.visibility=View.VISIBLE
                }
                1->{
                    itemState.text="已撤销"
                }
                2->{
                    itemState.text="处理中"
                    pg1.setBackgroundColor(Color.parseColor("#FFFF8FC1"))
                    pg2.setBackgroundColor(Color.parseColor("#FFFF8FC1"))
                    img2.setImageResource(R.drawable.img_zfdd_sected)
                }
                3->{
                    itemState.text="已完成"

                    pg1.setBackgroundColor(Color.parseColor("#FFFF8FC1"))
                    pg2.setBackgroundColor(Color.parseColor("#FFFF8FC1"))
                    pg3.setBackgroundColor(Color.parseColor("#FFFF8FC1"))
                    img2.setImageResource(R.drawable.img_zfdd_sected)
                    img3.setImageResource(R.drawable.ic_wc_sected)
                }
            }
        }catch (e:Exception){
            e.printStackTrace()
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode!=-1)return
        when(requestCode){
            GOTOFEE->{
                presenter?.getDetail(id,this)
                setResult(-1)
            }
        }

    }
    override fun bindView(): OrderView {
        return this
    }

    override fun createPresenter(): OrderDetailPresenter {
        return OrderDetailPresenter()
    }

    override val contentId: Int= R.layout.aty_order_detail
}